package jcu.ict.profaid;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

@SuppressLint("NewApi")
public class form_my_subject extends ListActivity{
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		ActionBar actionBar = getActionBar();
	    actionBar.setDisplayHomeAsUpEnabled(true);
		
		//initAdapter();
		registerForContextMenu(getListView());
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		new MenuInflater(this).inflate(R.menu.main, menu);

		EditText add = null;

		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
			View v = menu.findItem(R.id.add).getActionView();

			if (v != null) {
			add = (EditText) v.findViewById(R.id.titlesubject);
			}
		}

		if (add != null) {			//add.setOnEditorActionListener(onSearch);
		}

		return (super.onCreateOptionsMenu(menu));
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	        case android.R.id.home:
	            // app icon in action bar clicked; go home
	            Intent home = new Intent(this, MainActivity.class);
	            home.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	            startActivity(home);
	            return true;
	        case R.id.add:
	            // app icon in action bar clicked; go home
	            Intent adds = new Intent(this, form_add_subject.class);
	            adds.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	            startActivity(adds);
	            return (true);    
	        default:
	            return super.onOptionsItemSelected(item);
	            
	            
	    }
	}
	public class form_my_subject extends ListActivity{
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			SQLiteDatabase db = openOrCreateDatabase("MyDB", MODE_PRIVATE, null);
			db.execSQL("CREATE TABLE IF NOT EXISTS MYSUBJECT1 (course VARCHAR, sunjectcode NUMBER, NO.of Students NUMBER, History VARCHAR, Time NUMBER);");
			db.execSQL("INSERT INTO MYSUBJECT1 VALUES('mit', 2100, 30, 'march', 00);");
			db.execSQL("INSERT INTO MYSUBJECT1 VALUES('mit', 2200, 30, 'march', 02);");
			db.execSQL("INSERT INTO MYSUBJECT1 VALUES('mit', 2300, 30, 'march', 04);");
			db.execSQL("INSERT INTO MYSUBJECT1 VALUES('mit', 2400, 30, 'march', 06);");
			db.execSQL("INSERT INTO MYSUBJECT1 VALUES('mit', 2500, 30, 'march', 08);");
			db.execSQL("INSERT INTO MYSUBJECT1 VALUES('mit', 2600, 30, 'march', 10);");
			db.execSQL("INSERT INTO MYSUBJECT1 VALUES('mit', 2700, 30, 'march', 12);");
			db.close();
}
	}
}

